package org.xdemo.example.websocket.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by kz on 2017/8/7.
 */

@Controller
@RequestMapping("bootform")
public class BootStrapeController {

    @RequestMapping(value = "test3", method = RequestMethod.GET)
    public String toTest1() {
        return "testpages/test3";
    }

    @RequestMapping(value = "test3", method = RequestMethod.POST)
    public String toTestsubmit(HttpServletRequest request, String input1, Boolean checked, @RequestParam("file") MultipartFile file) {

        System.out.println(input1);
        System.out.println("" + checked);

        if (file == null) {
        } else if (file.getSize() == 0) {
            System.out.println("no file,return");
            return "redirect:/bootform/uploadfail";
        } else {

            System.out.println(file.getName() + file.getSize());
        }
//        MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest)request;
//        System.out.println("" + mRequest.getFile("file").getSize());
        return "testpages/test3";

    }


    @RequestMapping("uploadfail")
    public String uploadfail() {
        return "redirect:/bootform/test3";
    }

    @RequestMapping("test4")
    public String toRemoteMainUI() {
        return "forword:/org.xdemo.example.remoteUI/testform1";
    }

}
